package cn.ts.today_school.exception;

import cn.ts.today_school.common.JsonResult;
import cn.ts.today_school.common.StatusCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalException {

    @ExceptionHandler
    public JsonResult doHandleRuntimeException(MethodArgumentNotValidException ex){
        String message = ex.getFieldError().getDefaultMessage();
        return new JsonResult(StatusCode.OPERATION_FAILED,message);
    }
}
